﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Collections.Generic;

namespace SignalLab.BaseLibrary
{
  public abstract class RealTimeAnalyserBase : INotifyPropertyChanged
  {
    public int SampleRate { get; private set; }
    public int BitsPerSample { get; private set; }
    public RealTimeAnalyserBase(int sampleRate, int bitsPerSample)
    {
      SampleRate = sampleRate; BitsPerSample = bitsPerSample;
    }

    public virtual string Status
    {
      get
      {
        return _Status;
      }
      protected set
      {
        if (_Status != value)
        {
          _Status = value;
          RaisePropertyChanged("Status");
        }
      }
    }
    private string _Status;

    public abstract List<RealtimePropertyBase> GetProperties();
    
    public void SendData(byte[] bytes)
    {
      if (isStarted) recieveData(bytes);
    }

    protected bool isStarted;

    /// <summary>
    /// add analysis logic to this method. When analyser is started, this will be called everytime buffer on input device is ready
    /// </summary>
    protected abstract void recieveData(byte[] pcmData);

    public virtual void Start()
    {
      isStarted = true;
    }

    public virtual void Stop()
    {
      isStarted = false;
    }

    
    #region INotifyPropertyChanged members

    protected void RaisePropertyChanged(string propertyName)
    {
      if (PropertyChanged != null)
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }

    public event PropertyChangedEventHandler PropertyChanged;

    #endregion
  }
}
